/*
 * Copyright (c) 2011 Obix Labs Limited
 * Redistribution and use in source and binary forms, 
 * with or without modification, are permitted provided 
 * that the following conditions are met:
 * 
 * 		Redistribution of source code must retain the above 
 * 		copyright notice, this list of conditions and the 
 * 		following disclaimer.
 *
 * 		Redistribution in binary form must reproduce the 
 * 		above copyright notice, this list of conditions 
 * 		and the following disclaimer in the documentation 
 * 		and/or other materials provided with the distribution.
 * 
 * 	THIS SOFTWARE IS PROVIDED "AS IS," WITHOUT A WARRANTY OF 
 * 	ANY KIND. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS 
 * 	AND WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, 
 * 	FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, 
 * 	ARE HEREBY EXCLUDED. OBIX LABS LIMITED ("Obix Labs") AND ITS 
 * 	LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE 
 * 	AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR 
 * 	ITS DERIVATIVES. IN NO EVENT WILL Obix Labs OR ITS LICENSORS BE 
 * 	LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, 
 * 	INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE 
 * 	DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF 
 * 	LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE THIS 
 * 	SOFTWARE, EVEN IF Obix Labs HAS BEEN ADVISED OF THE POSSIBILITY OF 
 * 	SUCH DAMAGES.
 */

package com.obixlabs.commons.io;

import java.io.IOException;

import com.obixlabs.commons.io.FilePathConsoleInputHandler;
import com.obixlabs.commons.io.InteractiveCommandLineReader;

/*
 * Integration test for InteractiveCommandLineReader and FilePathConsoleInputHandler. Execution of this 
 * test does require human involvement, specifically for the supply of command line input. Alternatively this 
 * will have to be simulated somehow. 
 */
class FilePathConsoleReaderTst
{
	private String prompt;
	private String repeatPrompt;
	
	FilePathConsoleReaderTst()
        {
		prompt = "Please enter any valid file name";
		repeatPrompt = "Filename not valid. Puedo repetare?";
        }
	
	/*
	 * Test that a command line reader can be initialised with a file input handler.
	 * Handler is initialised to accept any path.
	 * Method simply echoes back the name of the read file.
	 */
	void testConsoleCallback() throws IOException
	{
		//E:\TemporaryFiles\delete\foo.bar
		FilePathConsoleInputHandler inputHandler = 
			new FilePathConsoleInputHandler(prompt, repeatPrompt, false);
		InteractiveCommandLineReader.prompt(inputHandler);
		System.out.println("\n\nRead file: " + inputHandler.getInputValue());
	}
	
        /*
         * Test that a command line reader can be initialised with a file input handler.
         * Handler is initialised to accept only paths to existing and readable files.
         * Method simply echoes back the name of the file.
         */	
	void testConsoleCallbackForExistingFile() throws IOException
	{
		//E:\TemporaryFiles\delete\re.pdf
		FilePathConsoleInputHandler inputHandler = 
			new FilePathConsoleInputHandler(prompt, repeatPrompt, true);		
		InteractiveCommandLineReader.prompt(inputHandler);
		System.out.println("\n\nRead file: " + inputHandler.getInputValue());		
	}
	
	/*
	 * Main/execution entry point.
	 */
	static void main(String[] args) throws IOException
	{
		FilePathConsoleReaderTst test = new FilePathConsoleReaderTst();
		test.testConsoleCallback();
		test.testConsoleCallbackForExistingFile();
	}
	
}
